package com.ux.iot.jetlinks.service.websocket;

import com.ux.iot.jetlinks.contant.JetlinksContants;
import lombok.extern.slf4j.Slf4j;

import javax.websocket.Session;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author caixiaodao
 * @version 1.0
 * session 管理器
 * @date 2021/11/15 13:27
 */
@Slf4j
public class SessionManager {
    final static Map<String, Session>  sessions=new ConcurrentHashMap<>();
    public static Session get(Object key) {
        return sessions.get(key);
    }

    /**
     * 获取单个session
     * @return
     */
    public static  Session getSingleSession(){
        return  sessions.get(JetlinksContants.SESSION_DEFAULT_KEY);
    }
    /**
     * 移除
     * @return
     */
    public static  Session removeSingleSession(){
        return  sessions.remove(JetlinksContants.SESSION_DEFAULT_KEY);
    }
    /**
     * 设置session 单个session
     * @return
     */
    public static  Session addSession(Session session){
        return  sessions.put(JetlinksContants.SESSION_DEFAULT_KEY,session);
    }
    public static Session put(String key, Session value) {
        return sessions.put(key, value);
    }

    public static Session remove(Object key) {
        return sessions.remove(key);
    }

    public static void putAll(Map<? extends String, ? extends Session> m) {
        sessions.putAll(m);
    }
}
